<script setup lang="ts">
import { Api } from '@/assets/apis';
import { ref, onMounted } from 'vue'
import type { HomeDataType } from '@/typings'
import { useRouter } from 'vue-router';
import { Toast } from 'vant';

const maleData = ref<Array<HomeDataType>>([])
const femaleData = ref<Array<HomeDataType>>([])
const router = useRouter()
const loading = ref(false)

onMounted(async () => {
    Toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0,
    });
    let { data } = await Api.getFreeMale()
    maleData.value = data.data.list
})
onMounted(async () => {
    let { data } = await Api.getFreeFemal()
    femaleData.value = data.data.list
    Toast.clear()
    loading.value = true
})

const detail = (id: string, title: string) => {
    router.push(`/book/${id}?title=${title}`)
}
</script>

<template>
    <div v-show="loading">
        <div class="list">
            <div class="title">
                <div class="title-name">男生限时免费</div>
                <div class="more">
                    更多
                </div>
            </div>
            <div class="more-list">
                <div class="more-item" v-for="b in maleData[0]?.list" @click="detail(b.id, b.title)">
                    <div class="more-poster">
                        <img :src="b.cover" alt="">
                    </div>
                    <div class="more-content">
                        <div class="content-name">{{ b.title }}</div>
                        <div class="content-author">{{ b.author }}</div>
                        <div class="content-desc">{{ b.content }}</div>
                        <div class="tags">
                            <span class="free">免费</span>
                            <span class="o-price">{{ b.p_action }}阅点</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="list">
            <div class="title">
                <div class="title-name">女生限时免费</div>
                <div class="more">
                    更多
                </div>
            </div>
            <div class="more-list">
                <div class="more-item" v-for="b in femaleData[1]?.list">
                    <div class="more-poster">
                        <img :src="b.cover" alt="">
                    </div>
                    <div class="more-content">
                        <div class="content-name">{{ b.title }}</div>
                        <div class="content-author">{{ b.author }}</div>
                        <div class="content-desc">{{ b.content }}</div>
                        <div class="tags">
                            <span class="free">免费</span>
                            <span class="o-price">{{ b.p_action }}阅点</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style lang="scss">
.list {
    width: 335rem;
    padding: 15rem 0 30rem 0;
    margin: 0 20rem 4rem 20rem;
    border-bottom: 1rem solid #ededed;

    .title {
        width: 335rem;
        height: 28rem;
        margin-bottom: 16rem;
        display: flex;
        justify-content: space-between;
        line-height: 28rem;

        .title-name {
            font-size: 20rem;
            font-weight: bold;
            color: #1a1a1a;
        }

        .more {
            color: #999;
            font-size: 13rem;
            border: 1rem solid #f0f0f0;
            padding: 0 17rem;
            border-radius: 28rem;
        }
    }

    .more-list {
        width: 335rem;
        margin-top: 8rem;

        .more-item {
            display: flex;
            margin-bottom: 20rem;

            .more-poster {
                width: 82rem;
                height: 115rem;
                margin-right: 15rem;

                img {
                    width: 100%;
                    height: 100%;
                    border-radius: 5rem;
                }
            }

            .more-content {
                width: 238rem;

                .content-name {
                    height: 20rem;
                    margin-bottom: 7rem;
                    font-size: 17rem;
                    color: #222;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }

                .content-author {
                    color: #999;
                    height: 14rem;
                    margin-bottom: 9rem;
                }

                .content-desc {
                    height: 36rem;
                    line-height: 18rem;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    font-size: 12rem;
                    color: #999;
                }

                .tags {
                    height: 22rem;
                    line-height: 22rem;
                    margin-top: 5rem;

                    .free {
                        color: #e64d2e;
                        margin-right: 4rem;
                    }

                    .o-price {
                        color: #999;
                        text-decoration: line-through;
                    }
                }
            }
        }
    }
}
</style>